<template>
    <div class="login-page">
        <transition name="form-fade" mode="in-out">
            <div class="form_contianer" v-show="showLogin">
                <div class="manage_tip">
                    <p>ijax后台管理系统</p>
                </div>
                <el-form :model="loginForm" :rules="rules" ref="loginForm">
                    <el-form-item prop="loginName">
                        <el-input
                                v-model="loginForm.loginName"
                                autocomplete="off"
                                placeholder="用户名"
                                prefix-icon="el-icon-ijax-user"
                                @keyup.enter.native="submitForm"
                        ></el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input
                                type="password"
                                v-model="loginForm.password"
                                autocomplete="off"
                                placeholder="密码"
                                prefix-icon="el-icon-ijax-password"
                                @keyup.enter.native="submitForm"
                        ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm" class="submit_btn">登陆</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </transition>
    </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        loginName: "",
        password: ""
      },
      rules: {
        loginName: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            max: 18,
            min: 6,
            message: "账号的最小长度为6位，最大长度为18位",
            trigger: "blur"
          }
        ]
      },
      showLogin: false
    };
  },
  mounted() {
    this.showLogin = true;
  },
  methods: {
    submitForm() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.$store.dispatch("Login", this.loginForm);
        }
      });
    }
  }
};
</script>


<style rel="stylesheet/scss" lang="scss" scoped>
@import "../assets/icon/iconfont.css";
@import "../../public/css/mixin.scss";

.login-page {
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: #324057;
}

.form_contianer {
  @include wh(320px, 210px);
  @include ctp(320px, 210px);
  padding: 40px 20px 0px 20px;
  border-radius: 5px;
  text-align: center;
  background-color: #fff;

  .submit_btn {
    width: 100%;
    font-size: 16px;
  }
}

.manage_tip {
  position: absolute;
  width: 100%;
  top: -100px;
  left: 0;

  p {
    font-size: 34px;
    color: #fff;
    text-align: center;
  }
}

.form-fade-enter-active,
.form-fade-leave-active {
  transition: all 1s;
}

.form-fade-enter,
.form-fade-leave-active {
  transform: translate3d(0, -50px, 0);
  opacity: 0;
}
</style>
